////////////////////////////////////////////////////////////////////////////////
//
//  Zemoga Inc
//  Copyright 2011 Zemoga Inc
//  All Rights Reserved.
//
////////////////////////////////////////////////////////////////////////////////
package com.videojukebox.components
{
	import ca.newcommerce.youtube.data.VideoData;
	import ca.newcommerce.youtube.feeds.VideoFeed;
	
	import com.videojukebox.application.AppController;
	import com.videojukebox.components.skins.VideosResultListBase;
	
	import mx.collections.ArrayList;
	import mx.events.FlexEvent;
	import mx.events.ItemClickEvent;
	
	
	/**
	 * Class description here
	 * 
	 * @author	davidnino	<email>
	 */
	public class VideosResultList extends VideosResultListBase
	{
		//------------------------------------------------------------------------------
		//
		//  Constants
		//
		//------------------------------------------------------------------------------
		
		//--------------------------------------
		//  Public
		//--------------------------------------
		
		//--------------------------------------
		//  Private
		//--------------------------------------
		
		//------------------------------------------------------------------------------
		//
		//  Static Methods
		//
		//------------------------------------------------------------------------------
		
		////////////////////////////////////////////////////////////////////////////////
		//
		//  Constructor
		//
		////////////////////////////////////////////////////////////////////////////////
		
		public function VideosResultList()
		{
			super();
			
			addEventListener(FlexEvent.CREATION_COMPLETE, creationComplete_handler);
		}
		
		//------------------------------------------------------------------------------
		//
		//  Variables
		//
		//------------------------------------------------------------------------------
		
		//--------------------------------------
		//  Public
		//--------------------------------------
		
		//--------------------------------------
		//  Private
		//--------------------------------------
		private var appController:AppController = AppController.getInstance();
		
		//------------------------------------------------------------------------------
		//
		//  Properties (getters/setters)
		//
		//------------------------------------------------------------------------------
		
		//------------------------------------------------------------------------------
		//
		//  Overriden methods
		//
		//------------------------------------------------------------------------------
		
		//------------------------------------------------------------------------------
		//
		//  Methods
		//
		//------------------------------------------------------------------------------
		
		//--------------------------------------
		//  Public
		//--------------------------------------
		
		//--------------------------------------
		//  Private
		//--------------------------------------
		private function addEventListeners():void
		{
			videoResultList.addEventListener(ItemClickEvent.ITEM_CLICK, videoResultItemclick_handler);	
		}
		
		public function setVideoSeachResult (data:VideoFeed):void{
			
			var resultArray:Array= [];
			var video:VideoData;
			
			while (video = data.next())
			{
				resultArray.push(video);
			}
			
			videoResultList.dataProvider = new ArrayList(resultArray);
			
		}
		
		//------------------------------------------------------------------------------
		//
		//  Event Handlers
		//
		//------------------------------------------------------------------------------
		protected function creationComplete_handler(event:FlexEvent):void
		{
			removeEventListener(FlexEvent.CREATION_COMPLETE, creationComplete_handler);
			addEventListeners();
		}
		
		protected function videoResultItemclick_handler(event:ItemClickEvent):void
		{
			trace("video click");
			//appController.application.videoplayer.loadVideo(event.item.data.id);
			appController.application.videoPlayer.loadVideo(event.item.data.id);
		}
	}
}